#!/usr/bin/env python
#
# Copyright 2008 Richard J. Bell. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

""" WikiGeometry classes for geo wiki (great-loop) site. """
# Python Imports

# Google App Engine Imports
from google.appengine.api import memcache
from google.appengine.ext import db

# Application Imports

class WikiGeometry(db.Model):
  name = db.StringProperty()
  description = db.StringProperty(multiline=True)
  type = db.StringProperty()
  dateModified = db.DateProperty(auto_now=True)
  coordinates = db.ListProperty(db.GeoPt, default=None)
  timeStamp = db.DateProperty(auto_now_add=True)
  userId = db.StringProperty(default=None)
  tags = db.ListProperty(unicode,default=None)
  bboxEast = db.FloatProperty()
  bboxWest = db.FloatProperty()
  bboxSouth = db.FloatProperty()
  bboxNorth = db.FloatProperty()
  geohash = db.StringProperty()

  def georssPoint(self):
    lat = float(self.coordinates[0].lat)
    lon = float(self.coordinates[0].lon)
    return ('%s %s' % (lat, lon))

  def georssBox(self):
    return ('%s %s %s %s' % (self.bboxSouth, self.bboxWest, self.bboxNorth,
                             self.bboxEast))
